#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
int main()
{
  printf("I am a process pid is %d\n",getpid());
  pid_t id=fork();

  if(id==0)
  {
    extern char** environ;
    sleep(3);
    printf("exec begin...\n");
    //putenv("myownenv=aaaaaaaaaaaaaaaaa");
    char*myenv[]=
    {
     (char*)"A=aaaaaaaa",
      (char*)"B=bbbbbbbb",
      (char*)"C=ccccccccc",
      NULL
    };
    char* arg[]={(char*)"ls",(char*)"-l",(char*)"-a",NULL};//char*为了不警告
    //execvp("ls",arg);
    //execvpe("ls",arg,myenv);
    execve("/usr/bin/ls",arg,myenv);
    //execle("./tmp","tmp",NULL,myenv);
    //execl("./tmp","tmp",NULL);
    //execlp("ls","ls","-a","-l",NULL);
    //char* arg[]={(char*)"ls",(char*)"-l",(char*)"-a",NULL};//char*为了不警告
    //execv("/usr/bin/ls",arg);
    //execl("/usr/bin/ls","ls","-a","-l",NULL);
   printf("hehe\n");
    exit(1);
  }
  pid_t rid=waitpid(id,NULL,0);
  if(rid>0)printf("wait success\n");
  return 0;
}
//int main()
//{
//
//  printf("I am a process pid is %d\n",getpid());
//  printf("exec begin...\n");
//  execl("./tmp","tmp",NULL);
//  return 0;
//}
//int main()
//{
//  printf("I am a process pid is %d\n",getpid());
//  printf("exec begin...\n");
//  execl("/usr/bin/ls","ls","-a","-l",NULL);//NULL不是"NULL"
//  printf("execl end\n");
//  return 0;
//}
